package com.yanti.controller;

import com.yanti.domain.ResponseResult;
import com.yanti.domain.dto.UserAnswerSubmitDTO;
import com.yanti.domain.vo.SubjectStudyTimeVo;
import com.yanti.filter.LoginUserContextHolder;
import com.yanti.service.UserAnswerDetailsService;
import com.yanti.service.UserCommitResultsService;
import com.yanti.service.UserDailyStudyTimeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/question")
public class UserAnswerDetailController {

    @Resource
    private UserAnswerDetailsService userAnswerDetailsService;

    @Resource
    private UserCommitResultsService userCommitResultsService;

    @Resource
    private UserDailyStudyTimeService userDailyStudyTimeService;

//    @PostMapping("/answerUpload")
//    public ResponseResult userUpLoadAnswer(@RequestBody UserAnswerSubmitDTO submitDTO){
//        return userAnswerDetailsService.userUpLoadAnswer(submitDTO);
//    }
    @GetMapping("/userQuestionCount")
    public ResponseResult<?> userQuestionCount(){
        // 计数逻辑需要更改
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
//        return userAnswerDetailsService.countQuestionsByUid(uid);
        return userDailyStudyTimeService.getUserQuestionCount(uid);
    }
    /**
     * 获取用户当天各科目的学习时间统计情况（没做的科目时间为0）
     * @return 包含每个科目学习时间等信息的列表
     */
    @GetMapping("/subjectStudyTimeToday")
    public ResponseResult getSubjectStudyTimeToday() {
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
        List<SubjectStudyTimeVo> studyTimeVos = userCommitResultsService.getSubjectStudyTimeToday(uid);
        return ResponseResult.okResult(studyTimeVos);
    }

    @GetMapping("/getTemporaryAnswerDetails")
    public ResponseResult getTemporaryAnswerDetails(@RequestParam String chapterId) {
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
        return userCommitResultsService.getTemporaryAnswerDetails(uid, chapterId);
    }
}